﻿using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

public class MD5Helper
{
    #region 获取MD5加密
    /// <summary>
    /// 获得32位的MD5加密
    /// </summary>
    /// <param name="input">输入字符串</param>
    /// <returns>返回值</returns>
    public static string GetMD532(string input)
    {
        MD5 md5 = MD5.Create();
        byte[] data = md5.ComputeHash(Encoding.Default.GetBytes(input));
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < data.Length; i++)
        {
            sb.Append(data[i].ToString("X2"));
        }
        return sb.ToString();
    }

    /// <summary>
    /// 获得16位的MD5加密
    /// </summary>
    /// <param name="input">输入字符串</param>
    /// <returns>返回值</returns>
    public static string GetMD516(string input)
    {
        return GetMD532(input).Substring(8, 16);
    }
    #endregion
}
